<?php


namespace App\Traits;
use Hyperf\Config\Config;
use Qiniu\Auth;

trait QiniuTraits
{
    /**
     * 鉴权
     */
    public function auth() {
        // 用于签名的公钥和私钥
        $config = config('qiniu.huadong');
        $accessKey = $config['AK'];
        $secretKey = $config['SK'];
        // 初始化签权对象
        return new Auth($accessKey, $secretKey);
    }

    public function load($key) {
        $auth = $this->auth();
        $config = config('qiniu.huadong');
        $baseUrl = $config['visit_url'];
        $baseUrl .= $key;
        // 对链接进行签名
        return $auth->privateDownloadUrl($baseUrl);
    }

    public function checkResponse($ret, $err){
        if ($ret == null) {
            // todo 记录日志
            return false;
        }
        return true;
    }
}